package com.xbts.web.controller.editor;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xbts.common.annotation.Log;
import com.xbts.common.core.controller.BaseController;
import com.xbts.common.core.domain.AjaxResult;
import com.xbts.common.enums.BusinessType;
import com.xbts.system.domain.SeiMaterialTemplate;
import com.xbts.system.service.ISeiMaterialTemplateService;
import com.xbts.common.utils.poi.ExcelUtil;
import com.xbts.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 模板素材关联Controller
 * @author xbts
 * @date 2023-09-08
 */
@Api("模板素材关联")
@RestController
@RequestMapping("/system/template/material")
public class SeiMaterialTemplateController extends BaseController {

    @Autowired
    private ISeiMaterialTemplateService seiMaterialTemplateService;

    /**
     * 查询模板素材关联列表
     */
    @ApiOperation("查询模板素材关联列表")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody SeiMaterialTemplate seiMaterialTemplate) {
        startPage();
        List<SeiMaterialTemplate> list = seiMaterialTemplateService.selectSeiMaterialTemplateList(seiMaterialTemplate);
        return getDataTable(list);
    }

    /**
     * 导出模板素材关联列表
     */
    @ApiOperation("导出模板素材关联列表")
    @Log(title = "模板素材关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,@RequestBody SeiMaterialTemplate seiMaterialTemplate) {
        List<SeiMaterialTemplate> list = seiMaterialTemplateService.selectSeiMaterialTemplateList(seiMaterialTemplate);
        ExcelUtil<SeiMaterialTemplate> util = new ExcelUtil<SeiMaterialTemplate>(SeiMaterialTemplate.class);
        util.exportExcel(response, list, "模板素材关联数据");
    }

    /**
     * 获取模板素材关联详细信息
     */
    @ApiOperation("获取模板素材关联详细信息")
    @ApiImplicitParam(name = "id", value = "模板素材关联ID", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(seiMaterialTemplateService.selectSeiMaterialTemplateById(id));
    }

    /**
     * 新增模板素材关联
     */
    @ApiOperation("新增模板素材关联")
    @Log(title = "模板素材关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SeiMaterialTemplate seiMaterialTemplate) {
        return toAjax(seiMaterialTemplateService.insertSeiMaterialTemplate(seiMaterialTemplate));
    }

    /**
     * 修改模板素材关联
     */
    @ApiOperation("修改模板素材关联")
    @Log(title = "模板素材关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SeiMaterialTemplate seiMaterialTemplate) {
        return toAjax(seiMaterialTemplateService.updateSeiMaterialTemplate(seiMaterialTemplate));
    }

    /**
     * 删除模板素材关联
     */
    @ApiOperation("删除模板素材关联")
    @ApiImplicitParam(name = "ids", value = "模板素材关联ID集合", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @Log(title = "模板素材关联", businessType = BusinessType.DELETE)
	@PostMapping("/batchDelete")
    public AjaxResult batchDelete(@RequestBody List<String> ids) {
        return toAjax(seiMaterialTemplateService.deleteSeiMaterialTemplateByIds(ids));
    }
}
